#include "gametest.h"
#include <string>

GameTest::GameTest(): Game(800,600,32,false)
{
    SDL_Color black = { 0x0, 0x0, 0x0, 0 };
    SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
    SDL_Color magenta =  { 0xFF, 0x0, 0xFF, 0 };

    std::string text("Masillas todos!");


    my_sprite = new Sprite("data/sample.png",128,126);
    my_bg = new Sprite("data/sample_bg.png",800,600);
    my_text = new TextSprite("data/VeraMono.ttf",text,black,white);

    my_sprite->x = my_sprite->y = 200;
    my_sprite->v_x = my_sprite->v_y = 0;

    my_bg->x = my_bg->y = 0;
    my_bg->frame_n = my_sprite->frame_n = 0;
}

GameTest::~GameTest()
{
    delete my_sprite;
    delete my_bg;
    delete my_text;
}

void GameTest::keyUp(const SDL_KeyboardEvent *key)
{
    switch ( key->keysym.sym )
    {
    case SDLK_LEFT:
    case SDLK_RIGHT:
        my_sprite->v_x = 0;
        break;
    case SDLK_UP:
    case SDLK_DOWN:
        my_sprite->v_y = 0;
        break;
    }
}


void GameTest::keyDown(const SDL_KeyboardEvent *key)
{
    switch ( key->keysym.sym )
    {
    case SDLK_LEFT:
        my_sprite->v_x = -5;
        break;
    case SDLK_RIGHT:
        my_sprite->v_x = 5;
        break;
    case SDLK_UP:
        my_sprite->v_y = -5;
        break;
    case SDLK_DOWN:
        my_sprite->v_y = 5;
        break;
    }
}

void GameTest::doDraw()
{
    my_bg->draw(screen);
    my_sprite->draw(screen);
    my_text->draw(screen);
    SDL_Flip(screen);
}

int GameTest::onLoop()
{
    my_sprite->frame_n = ++(my_sprite->frame_n)%5;
    my_sprite->update();
    return 0;
}
/* ex: set cindent expandtab softtabstop=4 shiftwidth=4 tabstop=4: */
